//
//  ContactSelectTableViewCell.m
//  BGM
//
//  Created by 我要变好看 on 2019/1/25.
//  Copyright © 2019 com.alirtc.demo. All rights reserved.
//

#import "ContactSelectTableViewCell.h"

#import "Common.h"
#import "UIImageView+WebCache.h"

@implementation ContactSelectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        
        self.cellBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 0, 52, 52)];
        [self.cellBtn setImage:[UIImage imageNamed:@"titleNormal"] forState:UIControlStateNormal];
        [self.cellBtn setImage:[UIImage imageNamed:@"tittleSele"] forState:UIControlStateSelected];
        [self addSubview:self.cellBtn];
        [self.cellBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        
        self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(70, 6, 40, 40)];
        self.headImage.layer.cornerRadius = 20;
        self.headImage.layer.masksToBounds = YES;
        [self addSubview:self.headImage];
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 0, 300, 52)];
        self.nameLabel.textColor = bgmmainColor;
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.nameLabel];
 
    }
    return self;
}

- (void)setFriendValue:(BGMuserFriendClass *)bgmfriend indexPath:(NSIndexPath *)indexPath isSele:(NSString *)isSele{
    
    self.indexPath = indexPath;
    self.cellBtn.tag = (int)indexPath.row;
    
    if ([isSele isEqualToString:@"0"]) {
        self.cellBtn.selected = NO;

    }else{
        self.cellBtn.selected = YES;
    }
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:bgmfriend.headImage] placeholderImage:[UIImage imageNamed:@"headImage"]];
    self.nameLabel.text = bgmfriend.name;
    
    
}

- (void)clickBtn:(UIButton *)btn{
    btn.selected = !btn.selected;
    [self.seleDelegate seleFriend:self.indexPath isSele:btn.selected];
}

@end
